package di

import (
	"context"
	"github.com/gin-gonic/gin"
	"time"

	"gitee.com/rzttw/grpc/internal/service"

	"git.huoys.com/middle-end/kratos/pkg/log"
	"git.huoys.com/middle-end/kratos/pkg/net/rpc/warden"
)


//go:generate kratos tool wire
type App struct {
	svc *service.Service
	http *gin.Engine
	grpc *warden.Server
}

func NewApp(svc *service.Service, h *gin.Engine, g *warden.Server) (app *App, closeFunc func(), err error) {
	app = &App{
		svc: svc,
		http: h,
		grpc: g,
	}
	closeFunc = func() {
		ctx, cancel := context.WithTimeout(context.Background(), 35*time.Second)
		if err := g.Shutdown(ctx); err != nil {
			log.Error("grpcSrv.Shutdown error(%v)", err)
		}
		// if err := h.Shutdown(ctx); err != nil {
		// 	log.Error("httpSrv.Shutdown error(%v)", err)
		// }
		svc.Close()
		cancel()
	}

	return
}
